<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>AppCore</title>
  <script src="../config.js"></script>
</head>

<body>
  <div style="width: 128px; height: 128px"></div>
</body>

</html>
<script>
  /// 这个脚本用来组织一些简单逻辑
  const _RIGHT_CHART_PAGE_NAME_ = "大屏右侧数据启动面板";

  // 1. 禁用本页面的鼠标和键盘事件
  Fuck("func_html_page", __self__, "raycast_filter", "true");

  // 2. 创建登录页面
  function CreateLoginPage() {
    var arg = {
      id: "LoginPage",
      x: -120,
      y: 0,
      width: 600,
      height: 645,
      anchor: 6,
      blur: true,
      radius: 6,
      source: window.iotWebConfig?.webUrl + "/pages/login/foreground.html",
      transform: "1,0.5",
      animation: {
        name: "fade+transform",
        from_x: 24,
      },
    };

    Fuck("func_html_page", null, "create_page", JSON.stringify(arg));
  }

  function OnReset() {
    Fuck("func_html_page", "_RDP_", "delete_page", null);
    Fuck("func_html_chrome", "_RDP_", "delete_page", null);
  }

  // 点击实体类型
  // 对应设备接口的id和deviceType字段(点击摄像头。 这里传入的是'视频'字符串)
  function OnClickEntity(deviceId, deviceType, identifier) {
    console.log(identifier);
    console.log(deviceType);

    let web_token = Fuck('func_db', null, 'get', JSON.stringify({
      key: 'web_token',
      default: ''
    }))
    let web_projId = Fuck('func_db', null, 'get', JSON.stringify({
      key: 'web_projId',
      default: ''
    }))
    if (!web_token) {
      console.error('未获取到token，请检查token是否正确')
      return
    }
    if (deviceType == "视频" || deviceType == "摄像头") {
      var page_url = window.iotWebConfig?.iotUrl + '/rtspVideoControl.html?name=' +
        identifier + '&token=' + web_token + '&projId=' + web_projId;
      CreateVideoPopupWindow(
        "SharedWindow",
        0,
        0,
        420,
        330,
        page_url,
        5,
        "0.5, 0",
        deviceId,
        "0,0,0"
      );
    } else if (deviceType == "温湿度") {
      var page_url = window.iotWebConfig?.webUrl + '/pageScreen/#/bigscreen/preview?code=component_FwHLYbStKM&name=' +
        identifier + '&token=' + web_token + '&projId=' + web_projId;
      CreateTemperaturePlane(
        "SharedWindow",
        0,
        0,
        280,
        180,
        page_url,
        5
      );
    }
    else {
      let device_url = window.iotWebConfig?.webUrl + '/pages/common/device.html?id=' + deviceId + '&name=' +
        identifier + '&token=' + web_token + '&projId=' + web_projId;
      CreateVideoPopupWindow(
        "SharedWindow",
        -300,
        0,
        650,
        430,
        device_url,
        5,
        "0.5,0.5",
        deviceId,
        "0,0,0"
      );
    }
  }

  // 按下快捷键打开或关闭编辑器触发
  function OnEditorPlayerChanged(open) {
    if (open) console.log("打开");
    else console.log("关闭");
  }

  // 点击了安防建筑，要模拟点击按钮
  function OnClickAnFangBuilding() {
    console.log("OnClickAnFangBuilding");
    FuckPage("Menu", "window.OnClickAnFangBuilding");
  }

  /// 离开作业系统
  function OnExitGameHandle(handle_name) {
    // 其它页面在创建页面的时候有填写一个group:_RDP_,（RightDataPlane), 几乎所有右侧面板都叫这个
    Fuck('func_html_page', '_RDP_', 'delete_page', null);
    Fuck('func_html_chrome', '_RDP_', 'delete_page', null);
    console.log('JS收到离开作业事件:' + handle_name)
  }

  /// 切换了作业系统系统，就是点击左侧菜单，作出反应后,
  function OnEnterGameHandle(row) {
    if (!row) {
      console.error("OnEnterGameHandle row is null");
      return;
    }

    let web_token = Fuck('func_db', null, 'get', JSON.stringify({
      key: 'web_token',
      default: ''
    }))
    let web_projId = Fuck('func_db', null, 'get', JSON.stringify({
      key: 'web_projId',
      default: ''
    }))
    if (!web_token) {
      console.error('未获取到token，请检查token是否正确')
      return
    }

    // 先关闭页面
    //OnExitGameHandle(row.name)
    console.log(row);
    var row_data = JSON.parse(row);

    // 创建子页面---------
    var page_id = row_data.id;
    switch (page_id) {
      case "ringPage1":
        CreateTemperaturePlane("CommonMessagePlane", -862, -290, 420, 176, window.iotWebConfig?.webUrl + '/pages/common/message.html?height=176&pageType=message&token=' + web_token + '&projId=' + web_projId, 3, false, false);
        Fuck("func_html_chrome", "CommonMessagePlane", "set_render_sort", 9999);
        break;
    }
    // ------------------

    console.log("JS:" + page_id);

    CreateOrSetUIPage(
      _RIGHT_CHART_PAGE_NAME_,
      -24,
      -140,
      0,
      0,
      window.iotWebConfig?.webUrl + "/pages" + row_data.value,
      1
    );
  }

  function CreateOrSetUIPage(id, x, y, width, height, source, anchor = 3) {
    var arg = {
      id,
      x,
      y,
      width,
      height,
      anchor: anchor,
      source,
      transform: "1,1",
      animation: {
        name: "fade+transform",
        from_x: 24,
      },
    };
    Fuck("func_html_page", null, "create_page", JSON.stringify(arg));
  }

  // 创建温度面板
  function CreateTemperaturePlane(id, x, y, width, height, source, anchor = 1, blur = true, close_button = true) {
    var arg = {
      id,
      x,
      y,
      width,
      height,
      anchor,
      source,
      transform: "0,0",
      blur,
      close_button,
      radius: 6,
      group: "_RDP_",
      /*bind3d: {
        type: "value",
        target: "0,0,0",
        offset: "0,0,0"
      },*/
      animation: {
        name: "fade+transform",
        from_x: 24,
      },
    };

    Fuck("func_html_chrome", null, "create_page", JSON.stringify(arg));
  }

  function CreateVideoPopupWindow(
    id,
    x,
    y,
    width,
    height,
    source,
    anchor = 1,
    transform = "0,1",
    deviceId,
    offset = "0,5,0"
  ) {
    var arg = {
      id,
      x,
      y,
      width,
      height,
      anchor,
      source,
      transform,
      blur: true,
      close_button: true,
      radius: 6,
      group: "_RDP_",
      bind3d: {
        type: "entity",
        target: deviceId,
        offset
      },
      animation: {
        name: "fade",
        from_x: 24,
      },
    };

    Fuck("func_html_chrome", null, "create_page", JSON.stringify(arg));
  }

  function CreateUPSPopupWindow(
    id,
    x,
    y,
    width,
    height,
    source,
    anchor = 5,
    transform = "0.5,0.5",
    deviceId
  ) {
    var arg = {
      id,
      x,
      y,
      width,
      height,
      anchor,
      source,
      transform,
      blur: true,
      close_button: true,
      radius: 6,
      group: "_RDP_",
      bind3d: {
        type: "entity",
        target: deviceId,
        offset: "0,5,0"
      },
      animation: {
        name: "fade",
        from_x: 24,
      },
    };

    Fuck("func_html_chrome", null, "create_page", JSON.stringify(arg));
  }

  CreateLoginPage();


</script>